<?php
/**
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file license.txt or that can be found at 
 * http://code.google.com/p/billboardce/wiki/License.
 *
 * @package    Slidetype_Flickr
 * @category   Slide Type
 * @license    http://code.google.com/p/billboardce/wiki/License New BSD License
 * @version    SVN: $Id: $
 */
class Slidetype_PhotoFeed extends Bbce_Slidetype_Abstract
{   
    /**
     * Title of the plugin, as shown in the interface
     * 
     * @var string
     */
    protected $_title = 'PhotoFeed';
    
    /**
     * Description of the plugin, as shown in the interface
     * 
     * @var string
     */
    protected $_description = 'Pull photos from a photo. Supported web apps: Flickr and Picasa';
    
    /**
     * Builds the slide requested.  Returns an associative
     * array of key => value pairs of variables to be assigned
     * to the view object.
     * 
     * Example:  return array('url' => 'http://www.google.com');
     * 
     * This will assign the value of "http://www.google.com" to the view
     * variable "url".  In the view, you will access this by "echo $this->url";
     * 
     * @param int $slideId
     * @return array
     */
    public function buildSlide($slideId)
    {
        $thisSlide = $this->find($slideId);

        $config = Zend_Registry::get('config');
      
        return array(
        	'feed'		  => $thisSlide['feed'],
        	'display'     => $thisSlide['display'],
            'embiggen'    => $thisSlide['embiggen'],
        	'random'	  => $thisSlide['randomSet'],
        	'titleShow'   => $thisSlide['titleShow'],
        	'hold'		  => $thisSlide['slideTime'],
            'bgColor'     => $thisSlide['bgColor'],
            'refreshTime' => $thisSlide['refreshTime']
        );
    }
    
    /**
     * Generates a thumbnail for the given slide.
     * 
     * @param $slideId
     * @return PHPGD image object
     */
    public function generateSlideThumbnail($slideId)
    {
        $path = realpath(APPLICATION_PATH . '/../loadable/slidetype/PhotoFeed/thumbnail.jpg');

        return imagecreatefromjpeg($path);
    }       
    
    /**
     * Generates a Zend_Form object which is displayed when
     * editing the given slide type.  The $values array is
     * a key => value associative array that maps the form
     * field names with their default values, if any.
     * 
     * @param array $values
     * @return object Zend_Form
     */
    public function getConfigurationForm($values = array())
    {
        $form = new Zend_Form();
        $form->setAttrib('class', 'slideTypeForm')
             ->setDecorators(array(
                     'FormElements',
                     array('HtmlTag', array('tag' => 'div', 'class' => 'zend_form')),
                     'Form'
             ));
        
        $feed = $form->createElement('text', 'feed', array('label' => 'PhotoFeed Feed:'));
        
        $refreshTime = $form->createElement('select', 'refreshTime', array('label' => 'Refresh feed every:'));
        $refreshTime->setMultiOptions(array(
            '1' => '1 minute',
            '2' => '2 minutes',
            '3' => '3 minutes',
            '4' => '4 minutes',
            '5' => '5 minutes',
            '10' => '10 minutes',
            '15' => '15 minutes',
            '30' => '30 minutes',
            '60' => '60 minutes'
        ));
        $refreshTime->setValue(isset($values['refreshTime']) ? $values['refreshTime'] : 10);
        
        $display = $form->createElement('select', 'display', array('label' => 'Display Type:'));
		$display->setMultiOptions(array(
			'standard' => 'Standard Slideshow',
		    'stack'    => 'Photo Stack',
			'wall'     => 'Photo Wall'
		));
		
		$embiggen = $form->createElement('select', 'embiggen', array('label' => 'Embiggen small images:'));
        $embiggen->setMultiOptions(array(
            '1' => 'Yes',
            '0'    => 'No'
        ));
        	
        $showTitle = $form->createElement('select', 'titleShow', array('label' => 'Show Title:'));
		$showTitle->setMultiOptions(array(
			'0' => "Don't show title",
			'1' => 'Show title'
		));
        
        $random = $form->createElement('select', 'randomSet', array('label' => 'Randomize:'));
		$random->setMultiOptions(array(
			'0' => 'No',
			'1' => 'Yes'
		));
        	
        $slideTime = $form->createElement('select', 'slideTime', array('label' => 'Slide time:'));
        $slideTime->setMultiOptions(array(
        	'1' => '1 second',
            '2' => '2 seconds',
            '3' => '3 seconds',
            '4' => '4 seconds',
            '5' => '5 seconds',
        	'5' => '5 seconds',
        	'10' => '10 seconds',
        	'15' => '15 seconds',
        	'30' => '30 seconds'
        ));
        $slideTime->setValue(isset($values['slideTime']) ? $values['slideTime'] : 5);
        
        $bgColor = $form->createElement('text', 'bgColor', array('label' => 'Background Color:'));
        $bgColor->setAttrib('size', 6)
                ->setAttrib('maxlength', 6)
                ->setAttrib('class', 'color');

        $bgColor->setValue(isset($values['bgColor']) ? $values['bgColor'] : '000000');
        
        $form->addElements(array($feed, $refreshTime, $display, $embiggen, $random, $showTitle, $slideTime, $bgColor));

        $form->setElementDecorators(array(
                  'ViewHelper',
                  'Errors',
                  array('HtmlTag', array('tag' => 'div', 'class' => 'elm')),
                  array('Label', array('tag' => 'span')),
              ));
        
        return $form;   
    }
}